<template>
	<view class="video_play">
		<image :src="videoObj.img" mode="widthFix"></image>
		<!-- 工具栏开始 -->
		<view class="video_tool">
			<view @click="muted=!muted" :class="['iconfont',muted?'iconjingyin':'iconshengyin']"></view>
			<view class="iconfont iconzhuanfa">
				<button open-type="share"></button>
			</view>
		</view>
		<!-- 工具栏结束 -->
		<!-- 视频开始 -->
		<view class="video_wrap">
			<!-- objectFit:'fill'表示当视频大小与视频容器不一致时进行完全填充 -->
			<video :muted="muted" :src="videoObj.video" objectFit="fill"></video>
		</view>
		<!-- 视频结束 -->
		<!-- 下载开始 -->
		<view class="video_download">
			<view class="download_btn" @click="handleDownload">下载高清</view>
		</view>
		<!-- 下载结束 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				videoObj: {},
				// 是否静音
				muted: false,
				// 标识是否点击下载
				downloadIf:false
			}
		},
		onLoad() {
			console.log('res', getApp().globalData);
			this.videoObj = getApp().globalData.video
		},
		methods: {
			// 下载视频
			async handleDownload() {
				await uni.showLoading({
					title: '下载中'
				})
				// 1.将远程文件下载到小程序内存中
				const {
					tempFilePath
				} = (await uni.downloadFile({
					url: this.videoObj.video
				}))[1]
				console.log('tempFile', tempFilePath);
				// 2.将内存的文件下载到本地中
				uni.saveVideoToPhotosAlbum({
					filePath: tempFilePath,
					success:()=>{
						console.log('成功调用了');
						uni.showToast({
							title:'下载成功',
							icon:'none'
						})
						
					},
					fail:()=>{
						console.log('调用失败了');
						uni.showToast({
							title:'下载失败',
							icon:'none'
						})
						
					}
				})
			
				
				
				uni.hideLoading()
				
				
				



			}
		}
	}
</script>

<style lang="scss" scoped>
	.video_play {
		position: relative;

		image {
			position: absolute;
			width: 100vw;
			height: 100vh;
			z-index: -1;
			// css3的滤镜
			filter: blur(20px);
		}

		.video_tool {
			display: flex;
			justify-content: flex-end;
			height: 80rpx;

			.iconfont {
				width: 80rpx;
				color: #FFFFFF;
				font-size: 50rpx;
				border-radius: 40rpx;
				display: flex;
				justify-content: center;
				background-color: rgba(0, 0, 0, .2);
				margin-right: 20rpx;
				align-items: center;

			}

			.iconzhuanfa {
				position: relative;

				button {
					position: absolute;
					width: 100%;
					height: 100%;
					opacity: 0;
				}
			}

		}

		.video_wrap {
			display: flex;
			justify-content: center;

			video {
				width: 360rpx;
				height: 600rpx;
			}
		}

		.video_download {

			display: flex;
			justify-content: center;
			margin-top: 30rpx;

			.download_btn {
				width: 360rpx;
				height: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: rgba(0, 0, 0, .6);
				border: 1rpx solid #FFFFFF;
				border-radius: 40rpx;
				color: #FFFFFF;
			}
		}
	}
</style>
